package charstream;

import java.io.*;

public class BufferedReaderDemo {
    public static void main(String[] args) {
        FileInputStream fis=null;
        FileOutputStream fos=null;
        InputStreamReader isr=null;//输入转换流
        OutputStreamWriter osw=null;//输出转换流
        BufferedReader br=null;
        BufferedWriter bw=null;
        try {
            fis=new FileInputStream("thread\\imooc.txt");
            fos=new FileOutputStream("thread\\imooc3.txt");
            isr=new InputStreamReader(fis,"UTF-8");
            osw=new OutputStreamWriter(fos,"UTF-8");
            br=new BufferedReader(isr);
            bw=new BufferedWriter(osw);
            int n=0;
            char[] cbuf=new char[100];
            while ((n=br.read(cbuf))!=-1){
                String s=new String(cbuf,0,n);
                //osw.write(cbuf,0,n);
                bw.write(s);
                bw.flush();
            }
            fis.close();
            fos.close();
            isr.close();
            osw.close();
            br.close();
            bw.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException("没找到该文件!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
